import 'dart:collection';
import 'dart:convert';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:group_button/group_button.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:shop/config/config.dart';
import 'package:shop/http/HttpUtil.dart';
import 'package:shop/route/my_route.dart';

import 'CartOrder.dart';
import 'Login.dart';

class GoodsDetail extends StatefulWidget {
  final String gid;         //商品ID
  Map goodsShop;            //该商品的购物车信息
  List cartList = [];       //购物车列表
  int cartSize=0;           //购物车数量
  String merchantName='';   //店铺名字
  String merchantId='';     //店铺id
  List goodsTypeList=[];    //一级类别的列表
  num zongjia=0.00;         //总价格
  num zongdabaofei=0.00;    //总打包费
  GoodsDetail({Key key, this.gid,this.goodsShop,this.cartList,this.cartSize,this.merchantId,this.merchantName,this.goodsTypeList,this.zongdabaofei,this.zongjia}) : super(key: key);

  @override
  _GoodsDetail createState() => _GoodsDetail(gid,goodsShop,cartList,cartSize,merchantId,merchantName,goodsTypeList,zongdabaofei,zongjia);
}

class _GoodsDetail extends State<GoodsDetail> {
  // 构造方法
  _GoodsDetail(gid,goodsShop,cartList,cartSize,merchantId,merchantName,goodsTypeList,zongdabaofei,zongjia) {
    this.goodsShop=goodsShop;
    this.cartList=cartList;
    this.cartsize=cartSize;
    this.merchantName=merchantName;
    this.merchantId=merchantId;
    this.goodsTypeList=goodsTypeList;
    this.zongjia=zongjia;
    this.zongdabaofei=zongdabaofei;
    _onLoading(gid);
  }

  List goodsTypeList=[];    //一级类别的列表
  String merchantName='';   //店铺名字
  String merchantId='';     //店铺id
  List cartList = [];       //购物车列表
  Map goodsShop= {};        //该商品的购物车信息
  var obj = {};             // 查询的商品
  var guige;                // 商品的规格
  double money = 0.00;      // 规格里选的价格
  String userId;            //用户ID
  List _imageUrls = [];     //定义图片存储的数组
  int cartsize=0;           //购物车数量
  num zongjia=0.0;          //总价格
  num zongdabaofei=0.0;     //总打包费
  num guigejia=0.0;         //规格价格
  var params = [];          //规格下标
  var names = [];           //选中的规格
  var panduan = [];         //判断规格是否选重复
  dynamic funCb;
  var guigeList;
  String guiges = "";       //字符串规格
  String guigexiabiao = ""; //字符串规格下标
  bool guanzhu = false;     //用户是否关注该商品服务

  // 获取数据
  void _onLoading(gid) async {

    SharedPreferences prefs = await SharedPreferences.getInstance();
    userId = prefs.getString("userId");
    // 此处不能获取上一个页面点击商品的id
    String url = "/waimai/mGoods/getMGoodsById?id=" + gid;
    var x = await HttpUtil().get(url);
    if (x['code'] == 200) {
      obj = x['data'];
      print(x['data']['goodsImageList']);
      String url = Config.getInstance().getHost();
      for (int i = 0; i < x['data']['goodsImageList'].length; i++) {
        _imageUrls.add(url + x['data']['goodsImageList'][i]['picture']);
      }

      String gDetail = x['data']['gdetail'];
      obj['gdetail'] = gDetail.replaceAll("src=\"/images/goods", "src=\"${url}images/goods");
    }

    var y = await HttpUtil().get("/waimai/merchant/merchantGuanzhu?userId="+userId+"&gid="+gid+"&type=1");
    if(y['code']==200){
      guanzhu = y['data'];
    }
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 464, height: 820);
    return new WillPopScope(
        onWillPop: () async {
          print("点击了返回");
          Map map=new Map();
          map['cartList']=cartList;
          map['goodsTypeList']=goodsTypeList;
          map['cartSize']=cartsize;
          map['zongjia']=zongjia;
          map['zongdabaofei']=zongdabaofei;
          MyRoute.pop(map);
          return true;
        },
        child: Scaffold(
            appBar: AppBar(
              leading: new IconButton(
                icon: new Icon(Icons.arrow_back, color: Colors.white),
                // onPressed: () => Navigator.of(context).pop(),
                onPressed: (){
                  Map map=new Map();
                  map['cartList']=cartList;
                  map['goodsTypeList']=goodsTypeList;
                  map['cartSize']=cartsize;
                  map['zongjia']=zongjia;
                  map['zongdabaofei']=zongdabaofei;
                  MyRoute.pop(map);
                },
              ),
              centerTitle: true,
              title: Text("商品详情"),
            ),
            body: Column(
              children: [
                Expanded(
                    child: Container(
                        child: ListView(
                          children: [
                            Container(
                              // 轮播图
                                width: ScreenUtil().setHeight(464),
                                height: ScreenUtil().setHeight(232),
                                child: Swiper(
                                    key: UniqueKey(),
                                    // 解决轮播图片大于3个的问题，是否有效待核实
                                    itemBuilder: _swiperBuilder,
                                    itemCount: _imageUrls.length,
                                    pagination: new SwiperPagination(
                                        builder: DotSwiperPaginationBuilder(
                                          color: Colors.black54,
                                          activeColor: Colors.white,
                                        )
                                    ),
                                    scrollDirection: Axis.horizontal,
                                    autoplay: true,
                                    autoplayDelay: 3000,
                                    onTap: (index) => print('点击了第$index个'))
                            ),
                            Container(
                              // 商品信息
                              child: Column(
                                children: [
                                  Row(
                                    children: [
                                      Expanded(child: Text("${obj['gname']}",style: TextStyle(fontSize: 20),))
                                    ],
                                  ),
                                  Row(
                                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                      children: [
                                        Text("￥${obj['gprice']}",
                                            style: TextStyle(color: Colors.red, fontSize: 20)),
                                        Container(
                                          child: Text("月销量:${obj['gsellnum']}"),
                                        )
                                      ]
                                  ),
                                  Container(
                                    child: Row(
                                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                      children: [
                                        Container(
                                          margin: EdgeInsets.only(left: 10),
                                          child: obj['qitianwuliyou'] == 1
                                              ? Text("7天无理由退换")
                                              : Text(""),
                                        ),
                                        Container(
                                          margin: EdgeInsets.only(right: ScreenUtil().setWidth(30)),
                                          child:
                                          obj['guige']==null || obj['guige'].length<=2
                                              ?
                                          Row(
                                            children: [
                                              GestureDetector(
                                                child: Container(
                                                  decoration: new BoxDecoration(
                                                    //背景
                                                    color: Colors.white,
                                                    //设置四周圆角 角度
                                                    borderRadius: BorderRadius.all(Radius.circular(4.0)),
                                                    //设置四周边框
                                                    border: new Border.all(width: 1, color: Colors.orangeAccent),
                                                  ),
                                                  alignment: Alignment.center,
                                                  width: 15,
                                                  height: 20,
                                                  child: Center(
                                                    child: Text("-"),
                                                  ),
                                                  padding: EdgeInsets.fromLTRB(1, 0, 0, 1),
                                                ),
                                                onTap: () async {
                                                  if(zongjia > 0 && goodsShop['catNum'] > 0){
                                                    zongjia = zongjia-goodsShop['gprice']-goodsShop['gdabaofei'];
                                                    zongdabaofei = zongdabaofei-goodsShop['gdabaofei'];
                                                    var x = await HttpUtil().get("/waimai/mShopCat/gaiNum?scatId=${goodsShop['catId']}&type=1");
                                                    if(x['code']==200){
                                                      for(int j=0;j<cartList.length;j++){
                                                        if(cartList[j]['userId']==userId && cartList[j]['mgid']==goodsShop['id']){
                                                          cartList[j]['scatNum']--;
                                                        }
                                                        if(cartList[j]['scatNum']==0){
                                                          cartList.removeAt(j);
                                                        }
                                                      }
                                                      cartsize--;
                                                      goodsShop['catNum']--;
                                                      setState(() {});
                                                    }
                                                  }
                                                },
                                              ),
                                              SizedBox(width: ScreenUtil().setWidth(4),),
                                              Container(
                                                width: 25,
                                                child: Center(
                                                  child:Text(goodsShop['catNum'].toString(),style: TextStyle(fontSize: 14),),
                                                ),
                                              ),
                                              SizedBox(width: ScreenUtil().setWidth(4),),
                                              GestureDetector(
                                                child: Container(
                                                  decoration: new BoxDecoration(
                                                    //背景
                                                    color: Colors.orangeAccent,
                                                    //设置四周圆角 角度
                                                    borderRadius: BorderRadius.all(Radius.circular(4.0)),
                                                    //设置四周边框
                                                    border: new Border.all(width: 1, color: Colors.orangeAccent),
                                                  ),
                                                  width: 15,
                                                  height: 20,
                                                  child: Center(
                                                    child: Text("+"),
                                                  ),
                                                  padding: EdgeInsets.fromLTRB(1, 0, 0, 1),
                                                ),
                                                onTap: () async {
                                                  if(userId==null || userId==""){
                                                    // Fluttertoast.showToast(msg: "请先登录");
                                                    Fluttertoast.showToast(
                                                        msg: "请先登录",
                                                        toastLength: Toast.LENGTH_SHORT,
                                                        gravity: ToastGravity.BOTTOM,
                                                        timeInSecForIosWeb: 1,
                                                        backgroundColor: Colors.black45,
                                                        textColor: Colors.white,
                                                        fontSize: 16.0
                                                    );
                                                    Future.delayed(Duration(seconds: 2), () {//延时2s跳转登录页面
                                                    });
                                                  }
                                                  var guige = goodsShop['guige'];//商品规格
                                                  // if(guige!=null && guige!=""){
                                                  if(guige.length>2){
                                                    params = []; //规格下标
                                                    names = []; //选中的规格
                                                    panduan = []; //判断规格是否选重复
                                                    guigejia = goodsShop['gprice'];//初始化规格价格
                                                    guigeList = json.decode(guige);//将规格转为数组
                                                    showDialog<Null>(
                                                      context: context,
                                                      barrierDismissible: true, // 点击窗口外部是否自动关闭
                                                      builder: (BuildContext context) {
                                                        return StatefulBuilder(builder: (context1, setBottomSheetState){
                                                          funCb = setBottomSheetState;
                                                          return new AlertDialog(
                                                            title: new Text(goodsShop['gname']),
                                                            content: new SingleChildScrollView(
                                                              child: new ListBody(
                                                                children: <Widget>[
                                                                  _showGuigeDetail(guigeList,),
                                                                ],
                                                              ),
                                                            ),
                                                            actions: <Widget>[
                                                              Text("价格:￥"),
                                                              Text("$guigejia",style: TextStyle(fontSize: 20,color: Colors.deepOrange),),
                                                              new FlatButton(
                                                                child: new Container(
                                                                  padding: EdgeInsets.symmetric(vertical: 3,horizontal: 6),
                                                                  decoration: BoxDecoration(
                                                                    borderRadius: BorderRadius.all(Radius.circular(5)) ,
                                                                    color: Colors.amberAccent,
                                                                  ),
                                                                  child: Text('+ 加入购物车',style: TextStyle(color: Colors.black),),
                                                                ),
                                                                onPressed: () async {
                                                                  int n = guigeList.length;
                                                                  int m = names.length;
                                                                  if (m < n) {
                                                                    Fluttertoast.showToast(msg: "请选择完整规格");
                                                                    return;
                                                                  }
                                                                  // params = params.sublist(params.length - n);
                                                                  // names = names.sublist(names.length - n);
                                                                  if (m > 1) {
                                                                    //排序
                                                                    for (int i = 0;i < n;i++) {
                                                                      if (guigeList[i]['name'] != panduan[i]) {
                                                                        for (int e = 0; e < panduan.length; e++) {
                                                                          if (guigeList[i]['name'] == panduan[e]) {
                                                                            var z = panduan[i];
                                                                            panduan[i] = panduan[e];
                                                                            panduan[e] = z;
                                                                            var y = names[i];
                                                                            names[i] = names[e];
                                                                            names[e] = y;
                                                                            var o = params[i];
                                                                            params[i] = params[e];
                                                                            params[e] = o;
                                                                          }
                                                                        }
                                                                      }
                                                                    }
                                                                  }
                                                                  guiges = json.encode(names);
                                                                  guigexiabiao = json.encode(params);
                                                                  zongjia = zongjia+guigejia+goodsShop['gdabaofei'];
                                                                  zongdabaofei = zongdabaofei+goodsShop['gdabaofei'];
                                                                  //加入购物车
                                                                  var x = await HttpUtil().get("/waimai/mShopCat/addMGoodscat?mgid=${goodsShop['id']}&userId=${userId}&catnum=1"+"&names="+guiges+"&params="+guigexiabiao+"&money="+goodsShop['gprice'].toString());
                                                                  if(x['code']==200){
                                                                    cartsize++;
                                                                    goodsShop['catId']=x['data'];
                                                                    goodsShop['catNum']++;
                                                                  }
                                                                  setState(() {});
                                                                  if (x['code'] == 200) {
                                                                    Fluttertoast.showToast(msg: "加入购物车成功");
                                                                  } else {
                                                                    Fluttertoast.showToast(msg: x['msg']);
                                                                  }
                                                                  Navigator.pop(context); // 隐藏底部规格选择
                                                                  // Navigator.of(context).pop();
                                                                },
                                                              ),
                                                            ],
                                                          );
                                                        },);
                                                      },
                                                    ).then((val) {
                                                    });
                                                  }else{
                                                    zongjia = zongjia+goodsShop['gprice']+goodsShop['gdabaofei'];
                                                    zongdabaofei = zongdabaofei+goodsShop['gdabaofei'];
                                                    //加入购物车
                                                    var x = await HttpUtil().get("/waimai/mShopCat/addMGoodscat?mgid=${goodsShop['id']}&userId=${userId}&catnum=1"+"&names=&params=&money="+goodsShop['gprice'].toString());
                                                    if(x['code']==200){
                                                      if(goodsShop['catNum']>0){
                                                        for(int j=0;j<cartList.length;j++){
                                                          if(cartList[j]['userId']==userId && cartList[j]['mgid']==goodsShop['id']){
                                                            cartList[j]['scatNum']++;
                                                          }
                                                        }
                                                      }else{
                                                        Map map={};
                                                        map['userId']=userId;
                                                        map['mgid']=goodsShop['id'];
                                                        map['scatNum']=1;
                                                        map['money']=goodsShop['gprice'];
                                                        map['id']=x['data'];
                                                        Map goodsmap={};
                                                        goodsmap['gimages']=goodsShop['gimages'];
                                                        goodsmap['guige']=goodsShop['guige'];
                                                        goodsmap['gname']=goodsShop['gname'];
                                                        goodsmap['gprice']=goodsShop['gprice'];
                                                        map['mgoods']=goodsmap;
                                                        cartList.add(map);
                                                      }
                                                      cartsize++;
                                                      goodsShop['catId']=x['data'];
                                                      goodsShop['catNum']++;
                                                    }
                                                    setState(() {});
                                                  }
                                                },
                                              )
                                            ],
                                          )
                                              :
                                          Row(
                                            children: [
                                              GestureDetector(
                                                child: Container(
                                                  decoration: new BoxDecoration(
                                                    //背景
                                                    color: Colors.orangeAccent,
                                                    //设置四周圆角 角度
                                                    borderRadius: BorderRadius.all(Radius.circular(4.0)),
                                                    //设置四周边框
                                                    border: new Border.all(width: 1, color: Colors.orangeAccent),
                                                  ),
                                                  width: 50,
                                                  child: Center(
                                                    child: Text("选规格",style: TextStyle(fontSize: 12),),
                                                  ),
                                                  padding: EdgeInsets.all(3),
                                                ),onTap: () async {

                                                if(userId==null || userId==""){
                                                  // Fluttertoast.showToast(msg: "请先登录");
                                                  Fluttertoast.showToast(
                                                      msg: "请先登录",
                                                      toastLength: Toast.LENGTH_SHORT,
                                                      gravity: ToastGravity.BOTTOM,
                                                      timeInSecForIosWeb: 1,
                                                      backgroundColor: Colors.black45,
                                                      textColor: Colors.white,
                                                      fontSize: 16.0
                                                  );
                                                  Future.delayed(Duration(seconds: 2), () {//延时2s跳转登录页面
                                                  });
                                                }
                                                var guige = goodsShop['guige'];//商品规格
                                                int guigeNum=0;
                                                int guigekucun=goodsShop['kucun'];
                                                if(guige.length>2){
                                                  params = []; //规格下标
                                                  names = []; //选中的规格
                                                  panduan = []; //判断规格是否选重复
                                                  guigejia = goodsShop['gprice'];//初始化规格价格
                                                  guigeList = json.decode(guige);//将规格转为数组
                                                  showModalBottomSheet(
                                                    context: context,
                                                    shape: new RoundedRectangleBorder(
                                                      borderRadius: BorderRadius.only(
                                                          topLeft: Radius.circular(20.0),
                                                          topRight: Radius.circular(20.0)),
                                                    ),
                                                    builder: (BuildContext context) {
                                                      return StatefulBuilder(
                                                        builder: (context1, setBottomSheetState){
                                                        return Container(
                                                          height:ScreenUtil().setHeight(600),
                                                          margin: EdgeInsets.only(left: 10),
                                                          child: Column(
                                                            crossAxisAlignment: CrossAxisAlignment.start,
                                                            children: [
                                                              Text(goodsShop['gname'],style: TextStyle(fontSize:26),),
                                                              Row(
                                                                children: [
                                                                  Text("￥",style: TextStyle(fontSize: 16,color: Colors.red),),
                                                                  Text("$guigejia",style: TextStyle(fontSize: 20,color: Colors.deepOrange),),
                                                                ],
                                                              ),
                                                              Row(
                                                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                                children: [
                                                                  Text("数量",style: TextStyle(fontSize: 20),),
                                                                  Row(
                                                                    children: [
                                                                      GestureDetector(
                                                                        child: Container(
                                                                          decoration: new BoxDecoration(
                                                                            //背景
                                                                            color: Colors.white,
                                                                            //设置四周圆角 角度
                                                                            borderRadius: BorderRadius.all(Radius.circular(4.0)),
                                                                            //设置四周边框
                                                                            border: new Border.all(width: 1, color: Colors.orangeAccent),
                                                                          ),
                                                                          alignment: Alignment.center,
                                                                          width: 18,
                                                                          height: 24,
                                                                          child: Center(
                                                                            child: Text("-"),
                                                                          ),
                                                                          padding: EdgeInsets.fromLTRB(1, 0, 0, 1),
                                                                        ),
                                                                        onTap: () async {
                                                                          if(userId==null || userId==""){
                                                                            Fluttertoast.showToast(
                                                                                msg: "请先登录",
                                                                                toastLength: Toast.LENGTH_SHORT,
                                                                                gravity: ToastGravity.BOTTOM,
                                                                                timeInSecForIosWeb: 1,
                                                                                backgroundColor: Colors.black45,
                                                                                textColor: Colors.white,
                                                                                fontSize: 16.0
                                                                            );
                                                                            Future.delayed(Duration(seconds: 2), () {//延时2s跳转登录页面
                                                                            });
                                                                          }
                                                                          if(guigeNum>=1){
                                                                            guigeNum--;
                                                                            setBottomSheetState((){ //底部弹窗更新

                                                                            });
                                                                          }
                                                                        },
                                                                      ),
                                                                      SizedBox(width: ScreenUtil().setWidth(8),),
                                                                      // Text(goodsList[i]['catNum'].toString()),
                                                                      Container(
                                                                        width: 25,
                                                                        child: Center(
                                                                          child:Text("$guigeNum",style: TextStyle(fontSize: 18),),
                                                                        ),
                                                                      ),
                                                                      SizedBox(width: ScreenUtil().setWidth(8),),
                                                                      GestureDetector(
                                                                        child: Container(
                                                                          decoration: new BoxDecoration(
                                                                            //背景
                                                                            color: Colors.orangeAccent,
                                                                            //设置四周圆角 角度
                                                                            borderRadius: BorderRadius.all(Radius.circular(4.0)),
                                                                            //设置四周边框
                                                                            border: new Border.all(width: 1, color: Colors.orangeAccent),
                                                                          ),
                                                                          width: 18,
                                                                          height: 24,
                                                                          child: Center(
                                                                            child: Text("+"),
                                                                          ),
                                                                          padding: EdgeInsets.fromLTRB(1, 0, 0, 1),
                                                                        ),
                                                                        onTap: () async {
                                                                          if(userId==null || userId==""){
                                                                            Fluttertoast.showToast(
                                                                                msg: "请先登录",
                                                                                toastLength: Toast.LENGTH_SHORT,
                                                                                gravity: ToastGravity.BOTTOM,
                                                                                timeInSecForIosWeb: 1,
                                                                                backgroundColor: Colors.black45,
                                                                                textColor: Colors.white,
                                                                                fontSize: 16.0
                                                                            );
                                                                            Future.delayed(Duration(seconds: 2), () {//延时2s跳转登录页面
                                                                            });
                                                                          }
                                                                          if(guigekucun<=guigeNum){
                                                                            Fluttertoast.showToast(
                                                                                msg: "库存不足",
                                                                                toastLength: Toast.LENGTH_SHORT,
                                                                                gravity: ToastGravity.BOTTOM,
                                                                                timeInSecForIosWeb: 1,
                                                                                backgroundColor: Colors.black45,
                                                                                textColor: Colors.white,
                                                                                fontSize: 16.0
                                                                            );
                                                                            return ;
                                                                          }
                                                                          guigeNum++;
                                                                          setBottomSheetState((){ //底部弹窗更新

                                                                          });
                                                                        },
                                                                      )
                                                                    ],
                                                                  )
                                                                ],
                                                              ),
                                                              Expanded(
                                                                child:SingleChildScrollView(
                                                                  child: new ListBody(
                                                                    children: <Widget>[
                                                                      _showGuigeDetail(guigeList,),
                                                                    ],
                                                                  ),
                                                                ),
                                                              ),
                                                              GestureDetector(
                                                                child: Container(
                                                                  margin: EdgeInsets.symmetric(horizontal: 10,vertical: 5),
                                                                  padding: EdgeInsets.symmetric(vertical: 5),
                                                                  decoration:  new BoxDecoration(
                                                                    //背景
                                                                    color: Colors.yellow,
                                                                    //设置四周圆角 角度
                                                                    borderRadius: BorderRadius.all(Radius.circular(20)),
                                                                    //设置四周边框
                                                                    border: new Border.all(width: 2, color: Colors.yellow),
                                                                  ),
                                                                  child: Center(
                                                                    child: Container(
                                                                      width: ScreenUtil().setWidth(450),
                                                                      margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                                                                      child: Row(
                                                                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                                                                        children: [
                                                                          Text("加入购物车")
                                                                        ],),
                                                                    ),
                                                                  ),
                                                                ),onTap: () async {
                                                                int n = guigeList.length;
                                                                int m = names.length;
                                                                if (m < n) {
                                                                  Fluttertoast.showToast(msg: "请选择完整规格");
                                                                  return;
                                                                }
                                                                if(guigeNum<=0){
                                                                  Fluttertoast.showToast(
                                                                      msg: "数量必须大于0",
                                                                      toastLength: Toast.LENGTH_SHORT,
                                                                      gravity: ToastGravity.BOTTOM,
                                                                      timeInSecForIosWeb: 1,
                                                                      backgroundColor: Colors.black45,
                                                                      textColor: Colors.white,
                                                                      fontSize: 16.0
                                                                  );
                                                                  return;
                                                                }
                                                                if (m > 1) {
                                                                  //排序
                                                                  for (int i = 0;i < n;i++) {
                                                                    if (guigeList[i]['name'] != panduan[i]) {
                                                                      for (int e = 0; e < panduan.length; e++) {
                                                                        if (guigeList[i]['name'] == panduan[e]) {
                                                                          var z = panduan[i];
                                                                          panduan[i] = panduan[e];
                                                                          panduan[e] = z;
                                                                          var y = names[i];
                                                                          names[i] = names[e];
                                                                          names[e] = y;
                                                                          var o = params[i];
                                                                          params[i] = params[e];
                                                                          params[e] = o;
                                                                        }
                                                                      }
                                                                    }
                                                                  }
                                                                }
                                                                guiges = json.encode(names);
                                                                guigexiabiao = json.encode(params);
                                                                zongjia = zongjia+guigejia+goodsShop['gdabaofei'];
                                                                zongdabaofei = zongdabaofei+goodsShop['gdabaofei'];
                                                                //加入购物车
                                                                var x = await HttpUtil().get("/waimai/mShopCat/addMGoodscat?mgid=${goodsShop['id']}&userId=${userId}&catnum="+guigeNum.toString()+"&names="+guiges+"&params="+guigexiabiao+"&money="+goodsShop['gprice'].toString());
                                                                if(x['code']==200){
                                                                  int xb=0;
                                                                  cartsize+=guigeNum;
                                                                  goodsShop['catId']=x['data'];
                                                                  goodsShop['catNum']++;
                                                                  for(int f=0;f<cartList.length;f++,xb++){
                                                                    if(goodsShop['id']==cartList[f]['mgid'] && guiges==cartList[f]['guiges'] && guigexiabiao==cartList[f]['guigeparams']){
                                                                      cartList[f]['scatNum']+=guigeNum;
                                                                      break;
                                                                    }
                                                                  }
                                                                  if(xb==cartList.length){
                                                                    Map map={};
                                                                    map['userId']=userId;
                                                                    map['mgid']=goodsShop['id'];
                                                                    map['scatNum']=guigeNum;
                                                                    map['money']=goodsShop['gprice'];
                                                                    map['id']=x['data'];
                                                                    map['guiges']=guiges;
                                                                    map['guigeparams']=guigexiabiao;
                                                                    Map goodsmap={};
                                                                    goodsmap['gimages']=goodsShop['gimages'];
                                                                    goodsmap['guige']=goodsShop['guige'];
                                                                    goodsmap['gname']=goodsShop['gname'];
                                                                    goodsmap['gprice']=goodsShop['gprice'];
                                                                    map['mgoods']=goodsmap;
                                                                    cartList.add(map);
                                                                  }
                                                                }
                                                                setState(() {});
                                                                if (x['code'] == 200) {
                                                                  Fluttertoast.showToast(msg: "加入购物车成功");
                                                                } else {
                                                                  Fluttertoast.showToast(msg: x['msg']);
                                                                }
                                                                Navigator.pop(context); // 隐藏底部规格选择
                                                                // Navigator.of(context).pop();
                                                              },
                                                              )
                                                            ],
                                                          )
                                                        );
                                                        //   new AlertDialog(
                                                        //   title: new Text(goodsShop['gname']),
                                                        //   content: new SingleChildScrollView(
                                                        //     child: new ListBody(
                                                        //       children: <Widget>[
                                                        //         _showGuigeDetail(guigeList,),
                                                        //       ],
                                                        //     ),
                                                        //   ),
                                                        //   actions: <Widget>[
                                                        //     Text("价格:￥"),
                                                        //     Text("$guigejia",style: TextStyle(fontSize: 20,color: Colors.deepOrange),),
                                                        //     new FlatButton(
                                                        //       child: new Container(
                                                        //         padding: EdgeInsets.symmetric(vertical: 3,horizontal: 6),
                                                        //         decoration: BoxDecoration(
                                                        //           borderRadius: BorderRadius.all(Radius.circular(5)) ,
                                                        //           color: Colors.amberAccent,
                                                        //         ),
                                                        //         child: Text('+ 加入购物车',style: TextStyle(color: Colors.black),),
                                                        //       ),
                                                        //       onPressed: () async {
                                                        //         int n = guigeList.length;
                                                        //         int m = names.length;
                                                        //         if (m < n) {
                                                        //           Fluttertoast.showToast(msg: "请选择完整规格");
                                                        //           return;
                                                        //         }
                                                        //         // params = params.sublist(params.length - n);
                                                        //         // names = names.sublist(names.length - n);
                                                        //         if (m > 1) {
                                                        //           //排序
                                                        //           for (int i = 0;i < n;i++) {
                                                        //             if (guigeList[i]['name'] != panduan[i]) {
                                                        //               for (int e = 0; e < panduan.length; e++) {
                                                        //                 if (guigeList[i]['name'] == panduan[e]) {
                                                        //                   var z = panduan[i];
                                                        //                   panduan[i] = panduan[e];
                                                        //                   panduan[e] = z;
                                                        //                   var y = names[i];
                                                        //                   names[i] = names[e];
                                                        //                   names[e] = y;
                                                        //                   var o = params[i];
                                                        //                   params[i] = params[e];
                                                        //                   params[e] = o;
                                                        //                 }
                                                        //               }
                                                        //             }
                                                        //           }
                                                        //         }
                                                        //         guiges = json.encode(names);
                                                        //         guigexiabiao = json.encode(params);
                                                        //         zongjia = zongjia+guigejia+goodsShop['gdabaofei'];
                                                        //         zongdabaofei = zongdabaofei+goodsShop['gdabaofei'];
                                                        //         //加入购物车
                                                        //         var x = await HttpUtil().get("/waimai/mShopCat/addMGoodscat?mgid=${goodsShop['id']}&userId=${userId}&catnum=1"+"&names="+guiges+"&params="+guigexiabiao+"&money="+goodsShop['gprice'].toString());
                                                        //         if(x['code']==200){
                                                        //           int xb=0;
                                                        //           cartsize++;
                                                        //           goodsShop['catId']=x['data'];
                                                        //           goodsShop['catNum']++;
                                                        //           for(int f=0;f<cartList.length;f++,xb++){
                                                        //             if(goodsShop['id']==cartList[f]['mgid'] && guiges==cartList[f]['guiges'] && guigexiabiao==cartList[f]['guigeparams']){
                                                        //               cartList[f]['scatNum']++;
                                                        //               break;
                                                        //             }
                                                        //           }
                                                        //           if(xb==cartList.length){
                                                        //             Map map={};
                                                        //             map['userId']=userId;
                                                        //             map['mgid']=goodsShop['id'];
                                                        //             map['scatNum']=1;
                                                        //             map['money']=goodsShop['gprice'];
                                                        //             map['id']=x['data'];
                                                        //             map['guiges']=guiges;
                                                        //             map['guigeparams']=guigexiabiao;
                                                        //             Map goodsmap={};
                                                        //             goodsmap['gimages']=goodsShop['gimages'];
                                                        //             goodsmap['guige']=goodsShop['guige'];
                                                        //             goodsmap['gname']=goodsShop['gname'];
                                                        //             goodsmap['gprice']=goodsShop['gprice'];
                                                        //             map['mgoods']=goodsmap;
                                                        //             cartList.add(map);
                                                        //           }
                                                        //         }
                                                        //         setState(() {});
                                                        //         if (x['code'] == 200) {
                                                        //           Fluttertoast.showToast(msg: "加入购物车成功");
                                                        //         } else {
                                                        //           Fluttertoast.showToast(msg: x['msg']);
                                                        //         }
                                                        //         Navigator.pop(context); // 隐藏底部规格选择
                                                        //         // Navigator.of(context).pop();
                                                        //       },
                                                        //     ),
                                                        //   ],
                                                        // );
                                                      },);
                                                    },
                                                  ).then((val) {
                                                  });
                                                }
                                              },
                                              )
                                            ],
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                  Container(
                                    padding: EdgeInsets.fromLTRB(6, 3, 6, 3),
                                    child: Row(
                                        children: [
                                          Expanded(child: Text("${obj['jianjie']}"),)
                                        ]
                                    ),
                                    decoration: BoxDecoration(),
                                  ),
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    children: [
                                      Container(
                                        child: Row(
                                          children: [
                                            GestureDetector(
                                              child: Container(
                                                // width: ScreenUtil().setWidth(65),
                                                child: Row(
                                                  // children: [Icon(CupertinoIcons.star), Text("收藏")])),
                                                  children: [
                                                    guanzhu ? Icon(Icons.star,color: Colors.orange,) : Icon(Icons.star_border),
                                                    Text("收藏")
                                                  ],)),
                                              onTap: () async {
                                                print("收藏服务");
                                                var map = new HashMap<String,dynamic>();
                                                map['gid']=obj['id'];map['type']=1;map['userId']=userId;
                                                Response response = await HttpUtil().post("waimai/mCollect/collect",map);
                                                var x = json.decode(response.toString());
                                                if(x['code']==200){
                                                  if(guanzhu){
                                                    guanzhu = false;
                                                  }else{
                                                    guanzhu = true;
                                                  }
                                                }
                                                Fluttertoast.showToast(msg: x['msg']);
                                                setState(() {

                                                });
                                              },
                                            ),
                                            // Icon(CupertinoIcons.heart),
                                            // Text("收藏")
                                          ],
                                        ),
                                      ),
                                      // Container(
                                      //   child: Row(
                                      //     children: [
                                      //       Icon(CupertinoIcons.arrowshape_turn_up_right),
                                      //       Text("分享")
                                      //     ],
                                      //   ),
                                      // )
                                    ],
                                  ),
                                ],
                              ),
                            ),
                            Html(
                              data: """${obj['gdetail']}""", // 富文本中的详情
                              style: {
                                // "html": Style(
                                //   backgroundColor: Colors.black12,
                                // ),
                              },
                            )
                          ],
                        )
                    )
                ),
                Container(
                  margin: EdgeInsets.symmetric(horizontal: 10,vertical: 5),
                  padding: EdgeInsets.symmetric(vertical: 5),
                  decoration:  new BoxDecoration(
                    //背景
                    color: Colors.black,
                    //设置四周圆角 角度
                    borderRadius: BorderRadius.all(Radius.circular(10)),
                    //设置四周边框
                    border: new Border.all(width: 1, color: Colors.black),
                  ),
                  child: Center(
                    child: Container(
                      width: ScreenUtil().setWidth(450),
                      decoration: BoxDecoration(
                        // borderRadius: BorderRadius.all(Radius.circular(30)) ,
                        // border: Border.all(color: Colors.black , width: 1) ,
                        color: Colors.black,
                      ),
                      margin: EdgeInsets.fromLTRB(0, 0, 0, 5),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [
                          GestureDetector(
                            child:Row(
                              children: [
                                Icon(Icons.shopping_cart,color: Colors.yellow,size: 35,),
                                Container(
                                  margin: EdgeInsets.fromLTRB(0, 0, 0, 20),
                                  padding: EdgeInsets.all(2),
                                  decoration: BoxDecoration(
                                    color: Colors.red,
                                    borderRadius:BorderRadius.circular(10),
                                  ),
                                  child: Row(
                                    children: [
                                      Text(cartsize.toString(),style: TextStyle(color: Colors.white,fontSize: 13),)
                                    ],
                                  ),
                                )
                              ],
                            ),onTap: (){
                            cartsize==0 ?
                            Fluttertoast.showToast(
                                msg: "您还未加入商品",
                                toastLength: Toast.LENGTH_SHORT,
                                gravity: ToastGravity.BOTTOM,
                                timeInSecForIosWeb: 1,
                                backgroundColor: Colors.black45,
                                textColor: Colors.white,
                                fontSize: 16.0
                            )
                                :
                            showDialog<Null>(//展示购物车的窗口
                              context: context,
                              barrierDismissible: true, // 点击窗口外部是否自动关闭
                              builder: (BuildContext context) {
                                return StatefulBuilder(
                                  builder: (context1,state){
                                    funCb = state;
                                    return new AlertDialog(
                                      title: new Text("购物车"),
                                      content: new SingleChildScrollView(
                                        child: new ListBody(
                                          children: <Widget>[
                                            showCart(cartList,state,context)
                                          ],
                                        ),
                                      ),
                                    );
                                  },
                                );
                              },
                            ).then((val) {

                            });
                          },
                          ),
                          Container(
                            // color: Colors.red,
                            margin: EdgeInsets.fromLTRB(0, 0, 100, 0),
                            // padding: EdgeInsets.fromLTRB(0, 0, 150, 0),
                            child: Text("￥${zongjia.toStringAsFixed(2)}",style: TextStyle(color: Colors.white,fontSize: 20),),
                          ),
                          GestureDetector(
                            child: Container(
                              padding: EdgeInsets.symmetric(vertical: 10,horizontal: 20),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.all(Radius.circular(30)) ,
                                border: Border.all(color: Colors.yellow , width: 1) ,
                                color: Colors.yellow,
                              ),
                              child: Text("去结算",style: TextStyle(color: Colors.black),),
                            ),
                            onTap: () async {
                              // double peisongfei = 10;//配送费
                              // var x = await HttpUtil().get("/waimai/mOder/catSubmitMOrder?userId=$userId&mid=$merchantId&orPeisongtype=2&orRemark=&dabaofei=$zongdabaofei&peisongfei="+peisongfei.toString()+"&orPrice=$zongjiage");
                              if(cartsize>0){
                                //跳订单页面
                                var value = await MyRoute.push(CartOrder(orRemark: "",cartList: cartList,merchantName: merchantName,dabaofei: zongdabaofei,zongjia: zongjia.toString(),cartsize: cartsize,merchantId: merchantId,));
                                if(value==1){
                                  for(int x=0;x<cartList.length;x++){
                                    cartList.removeAt(x);
                                  }
                                  goodsShop["catNum"]=0;
                                  zongdabaofei=0;
                                  zongjia=0;
                                  setState(() {

                                  });
                                }
                              }else{
                                Fluttertoast.showToast(
                                    msg: "请先选择商品",
                                    toastLength: Toast.LENGTH_SHORT,
                                    gravity: ToastGravity.BOTTOM,
                                    timeInSecForIosWeb: 1,
                                    backgroundColor: Colors.black45,
                                    textColor: Colors.white,
                                    fontSize: 16.0
                                );
                              }
                            },
                          )
                        ],),
                    ),
                  ),
                )
                // Row(
                //   children: [
                //     Container(
                //       child:
                //           Column(children: [Icon(CupertinoIcons.cube), Text("店铺")]),
                //       width: ScreenUtil().setWidth(58),
                //       decoration: BoxDecoration(),
                //     ),
                //     Container(
                //         width: ScreenUtil().setWidth(58),
                //         child: Column(children: [
                //           Icon(CupertinoIcons.headphones),
                //           Text("客服")
                //         ])),
                //     Container(
                //         width: ScreenUtil().setWidth(58),
                //         child: Column(
                //             children: [Icon(CupertinoIcons.star), Text("收藏")]
                //         )
                //     ),
                //     Expanded(child: Text("")),
                //     GestureDetector(
                //         child: Container(
                //           margin: EdgeInsets.only(right: 10),
                //           width: ScreenUtil().setWidth(145),
                //           height: ScreenUtil().setHeight(50),
                //           child: Center(
                //               child: Text("加入购物车",
                //                   style: TextStyle(color: Colors.white))
                //           ),
                //           decoration: BoxDecoration(color: Colors.amberAccent),
                //         ),
                //         onTap: () async {
                //           String names = ""; //规格
                //           String params = ""; //规格下标
                //           money = obj['gprice']; //金额
                //           SharedPreferences prefs = await SharedPreferences.getInstance();
                //           userId = prefs.getString("userId"); //用户ID
                //           if (userId == null || userId == "") {
                //             Fluttertoast.showToast(msg: "请先登录");
                //             //延时2s执行返回
                //             Future.delayed(Duration(seconds: 2), () {
                //               MyRoute.replace(Login());
                //             });
                //           }
                //           //加入购物车
                //           if (guige == null) {
                //             // 如果没有规格
                //             var x = await HttpUtil().get(
                //                 "/app/shopCat/addGoodscat?gid=" +
                //                     "${obj['gid']}" +
                //                     "&userId=" +
                //                     userId +
                //                     "&catnum=1" +
                //                     "&names=" +
                //                     names +
                //                     "&params=" +
                //                     params +
                //                     "&money=" +
                //                     money.toString());
                //             if (x['code'] == 200) {
                //               Fluttertoast.showToast(msg: "加入购物车成功");
                //             } else {
                //               Fluttertoast.showToast(msg: x['msg']);
                //             }
                //           } else {
                //             // 显示规格
                //             showModalBottomSheet(
                //               context: context,
                //               builder: (BuildContext context) {
                //                 return _showGuige(1);
                //               },
                //             ).then((val) {
                //               print(val);
                //             });
                //           }
                //         }),
                //     // GestureDetector(
                //     //   child: Container(
                //     //     width: ScreenUtil().setWidth(145),
                //     //     height: ScreenUtil().setHeight(50),
                //     //     child: Center(
                //     //         child: Text(
                //     //       "立即购买",
                //     //       style: TextStyle(color: Colors.white),
                //     //     )),
                //     //     decoration: BoxDecoration(color: Colors.red),
                //     //   ),
                //     //   onTap: () async {
                //     //     SharedPreferences prefs =
                //     //         await SharedPreferences.getInstance();
                //     //     // String userId = prefs.getString("userId");//用户ID
                //     //     bool isLogin = prefs.getBool("isLogin");
                //     //     if (!isLogin) {
                //     //       Fluttertoast.showToast(msg: "请先登录");
                //     //       Future.delayed(Duration(seconds: 2), () {
                //     //         MyRoute.replace(Login());
                //     //       });
                //     //     } else {
                //     //       //传商品ID，商品名称，商品价格，商品图片，商品单位，运费，规格，规格下标
                //     //       if (guige == null) {
                //     //         String gid = obj['gid'];
                //     //         MyRoute.push(LjgmOrder(
                //     //             gid: gid, names: guiges, params: guigexiabiao));
                //     //       } else {
                //     //         // 显示规格
                //     //         showModalBottomSheet(
                //     //           context: context,
                //     //           builder: (BuildContext context) {
                //     //             return _showGuige(2);
                //     //           },
                //     //         ).then((val) {
                //     //           print(val);
                //     //         });
                //     //       }
                //     //     }
                //     //   },
                //     // )
                //   ],
                // )
              ],
            ))
    );
    Scaffold(
        appBar: AppBar(
          leading: new IconButton(
            icon: new Icon(Icons.arrow_back, color: Colors.white),
            // onPressed: () => Navigator.of(context).pop(),
            onPressed: (){
              Map map=new Map();
              map['cartList']=cartList;
              map['goodsTypeList']=goodsTypeList;
              map['cartSize']=cartsize;
              map['zongjia']=zongjia;
              map['zongdabaofei']=zongdabaofei;
              MyRoute.pop(map);
            },
          ),
          centerTitle: true,
          title: Text("商品详情"),
        ),
        body: Column(
          children: [
            Expanded(
                child: Container(
                    child: ListView(
                    children: [
                      Container(
                          // 轮播图
                          width: ScreenUtil().setHeight(464),
                          height: ScreenUtil().setHeight(232),
                          child: Swiper(
                              key: UniqueKey(),
                              // 解决轮播图片大于3个的问题，是否有效待核实
                              itemBuilder: _swiperBuilder,
                              itemCount: _imageUrls.length,
                              pagination: new SwiperPagination(
                                builder: DotSwiperPaginationBuilder(
                                  color: Colors.black54,
                                  activeColor: Colors.white,
                                )
                              ),
                              scrollDirection: Axis.horizontal,
                              autoplay: true,
                              autoplayDelay: 3000,
                              onTap: (index) => print('点击了第$index个'))
                      ),
                      Container(
                        // 商品信息
                        child: Column(
                          children: [
                            Row(
                              children: [
                                Expanded(child: Text("${obj['gname']}",style: TextStyle(fontSize: 20),))
                              ],
                            ),
                            Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text("￥${obj['gprice']}",
                                  style: TextStyle(color: Colors.red, fontSize: 20)),
                                  Container(
                                    child: Text("月销量:${obj['gsellnum']}"),
                                  )
                                ]
                            ),
                            Container(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Container(
                                    child: obj['qitianwuliyou'] == 1
                                        ? Text("7天无理由退换")
                                        : Text(""),
                                  ),
                                  obj['guige']==null || obj['guige'].length<=2
                                      ?
                                  Row(
                                    children: [
                                      GestureDetector(
                                        child: Container(
                                          decoration: new BoxDecoration(
                                            //背景
                                            color: Colors.white,
                                            //设置四周圆角 角度
                                            borderRadius: BorderRadius.all(Radius.circular(4.0)),
                                            //设置四周边框
                                            border: new Border.all(width: 1, color: Colors.orangeAccent),
                                          ),
                                          alignment: Alignment.center,
                                          width: 15,
                                          height: 20,
                                          child: Center(
                                            child: Text("-"),
                                          ),
                                          padding: EdgeInsets.fromLTRB(1, 0, 0, 1),
                                        ),
                                        onTap: () async {
                                          if(zongjia > 0 && goodsShop['catNum'] > 0){
                                            zongjia = zongjia-goodsShop['gprice']-goodsShop['gdabaofei'];
                                            zongdabaofei = zongdabaofei-goodsShop['gdabaofei'];
                                            var x = await HttpUtil().get("/waimai/mShopCat/gaiNum?scatId=${goodsShop['catId']}&type=1");
                                            if(x['code']==200){
                                              for(int j=0;j<cartList.length;j++){
                                                if(cartList[j]['userId']==userId && cartList[j]['mgid']==goodsShop['id']){
                                                  cartList[j]['scatNum']--;
                                                }
                                                if(cartList[j]['scatNum']==0){
                                                  cartList.removeAt(j);
                                                }
                                              }
                                              cartsize--;
                                              goodsShop['catNum']--;
                                              setState(() {});
                                            }
                                          }
                                        },
                                      ),
                                      SizedBox(width: ScreenUtil().setWidth(4),),
                                      Container(
                                        width: 25,
                                        child: Center(
                                          child:Text(goodsShop['catNum'].toString(),style: TextStyle(fontSize: 14),),
                                        ),
                                      ),
                                      SizedBox(width: ScreenUtil().setWidth(4),),
                                      GestureDetector(
                                        child: Container(
                                          decoration: new BoxDecoration(
                                            //背景
                                            color: Colors.orangeAccent,
                                            //设置四周圆角 角度
                                            borderRadius: BorderRadius.all(Radius.circular(4.0)),
                                            //设置四周边框
                                            border: new Border.all(width: 1, color: Colors.orangeAccent),
                                          ),
                                          width: 15,
                                          height: 20,
                                          child: Center(
                                            child: Text("+"),
                                          ),
                                          padding: EdgeInsets.fromLTRB(1, 0, 0, 1),
                                        ),
                                        onTap: () async {
                                          if(userId==null || userId==""){
                                            // Fluttertoast.showToast(msg: "请先登录");
                                            Fluttertoast.showToast(
                                                msg: "请先登录",
                                                toastLength: Toast.LENGTH_SHORT,
                                                gravity: ToastGravity.BOTTOM,
                                                timeInSecForIosWeb: 1,
                                                backgroundColor: Colors.black45,
                                                textColor: Colors.white,
                                                fontSize: 16.0
                                            );
                                            Future.delayed(Duration(seconds: 2), () {//延时2s跳转登录页面
                                            });
                                          }
                                          var guige = goodsShop['guige'];//商品规格
                                          // if(guige!=null && guige!=""){
                                          if(guige.length>2){
                                            params = []; //规格下标
                                            names = []; //选中的规格
                                            panduan = []; //判断规格是否选重复
                                            guigejia = goodsShop['gprice'];//初始化规格价格
                                            guigeList = json.decode(guige);//将规格转为数组
                                            showDialog<Null>(
                                              context: context,
                                              barrierDismissible: true, // 点击窗口外部是否自动关闭
                                              builder: (BuildContext context) {
                                                return StatefulBuilder(builder: (context1, setBottomSheetState){
                                                  funCb = setBottomSheetState;
                                                  return new AlertDialog(
                                                    title: new Text(goodsShop['gname']),
                                                    content: new SingleChildScrollView(
                                                      child: new ListBody(
                                                        children: <Widget>[
                                                          _showGuigeDetail(guigeList,),
                                                        ],
                                                      ),
                                                    ),
                                                    actions: <Widget>[
                                                      Text("价格:￥"),
                                                      Text("$guigejia",style: TextStyle(fontSize: 20,color: Colors.deepOrange),),
                                                      new FlatButton(
                                                        child: new Container(
                                                          padding: EdgeInsets.symmetric(vertical: 3,horizontal: 6),
                                                          decoration: BoxDecoration(
                                                            borderRadius: BorderRadius.all(Radius.circular(5)) ,
                                                            color: Colors.amberAccent,
                                                          ),
                                                          child: Text('+ 加入购物车',style: TextStyle(color: Colors.black),),
                                                        ),
                                                        onPressed: () async {
                                                          int n = guigeList.length;
                                                          int m = names.length;
                                                          if (m < n) {
                                                            Fluttertoast.showToast(msg: "请选择完整规格");
                                                            return;
                                                          }
                                                          // params = params.sublist(params.length - n);
                                                          // names = names.sublist(names.length - n);
                                                          if (m > 1) {
                                                            //排序
                                                            for (int i = 0;i < n;i++) {
                                                              if (guigeList[i]['name'] != panduan[i]) {
                                                                for (int e = 0; e < panduan.length; e++) {
                                                                  if (guigeList[i]['name'] == panduan[e]) {
                                                                    var z = panduan[i];
                                                                    panduan[i] = panduan[e];
                                                                    panduan[e] = z;
                                                                    var y = names[i];
                                                                    names[i] = names[e];
                                                                    names[e] = y;
                                                                    var o = params[i];
                                                                    params[i] = params[e];
                                                                    params[e] = o;
                                                                  }
                                                                }
                                                              }
                                                            }
                                                          }
                                                          guiges = json.encode(names);
                                                          guigexiabiao = json.encode(params);
                                                          zongjia = zongjia+guigejia+goodsShop['gdabaofei'];
                                                          zongdabaofei = zongdabaofei+goodsShop['gdabaofei'];
                                                          //加入购物车
                                                          var x = await HttpUtil().get("/waimai/mShopCat/addMGoodscat?mgid=${goodsShop['id']}&userId=${userId}&catnum=1"+"&names="+guiges+"&params="+guigexiabiao+"&money="+goodsShop['gprice'].toString());
                                                          if(x['code']==200){
                                                            cartsize++;
                                                            goodsShop['catId']=x['data'];
                                                            goodsShop['catNum']++;
                                                          }
                                                          setState(() {});
                                                          if (x['code'] == 200) {
                                                            Fluttertoast.showToast(msg: "加入购物车成功");
                                                          } else {
                                                            Fluttertoast.showToast(msg: x['msg']);
                                                          }
                                                          Navigator.pop(context); // 隐藏底部规格选择
                                                          // Navigator.of(context).pop();
                                                        },
                                                      ),
                                                    ],
                                                  );
                                                },);
                                              },
                                            ).then((val) {
                                            });
                                          }else{
                                            zongjia = zongjia+goodsShop['gprice']+goodsShop['gdabaofei'];
                                            zongdabaofei = zongdabaofei+goodsShop['gdabaofei'];
                                            //加入购物车
                                            var x = await HttpUtil().get("/waimai/mShopCat/addMGoodscat?mgid=${goodsShop['id']}&userId=${userId}&catnum=1"+"&names=&params=&money="+goodsShop['gprice'].toString());
                                            if(x['code']==200){
                                              if(goodsShop['catNum']>0){
                                                for(int j=0;j<cartList.length;j++){
                                                  if(cartList[j]['userId']==userId && cartList[j]['mgid']==goodsShop['id']){
                                                    cartList[j]['scatNum']++;
                                                  }
                                                }
                                              }else{
                                                Map map={};
                                                map['userId']=userId;
                                                map['mgid']=goodsShop['id'];
                                                map['scatNum']=1;
                                                map['money']=goodsShop['gprice'];
                                                map['id']=x['data'];
                                                Map goodsmap={};
                                                goodsmap['gimages']=goodsShop['gimages'];
                                                goodsmap['guige']=goodsShop['guige'];
                                                goodsmap['gname']=goodsShop['gname'];
                                                goodsmap['gprice']=goodsShop['gprice'];
                                                map['mgoods']=goodsmap;
                                                cartList.add(map);
                                              }
                                              cartsize++;
                                              goodsShop['catId']=x['data'];
                                              goodsShop['catNum']++;
                                            }
                                            setState(() {});
                                          }
                                        },
                                      )
                                    ],
                                  )
                                      :
                                  Row(
                                    children: [
                                      GestureDetector(
                                        child: Container(
                                          decoration: new BoxDecoration(
                                            //背景
                                            color: Colors.orangeAccent,
                                            //设置四周圆角 角度
                                            borderRadius: BorderRadius.all(Radius.circular(4.0)),
                                            //设置四周边框
                                            border: new Border.all(width: 1, color: Colors.orangeAccent),
                                          ),
                                          width: 50,
                                          child: Center(
                                            child: Text("选规格",style: TextStyle(fontSize: 12),),
                                          ),
                                          padding: EdgeInsets.all(3),
                                        ),onTap: () async {

                                        if(userId==null || userId==""){
                                          // Fluttertoast.showToast(msg: "请先登录");
                                          Fluttertoast.showToast(
                                              msg: "请先登录",
                                              toastLength: Toast.LENGTH_SHORT,
                                              gravity: ToastGravity.BOTTOM,
                                              timeInSecForIosWeb: 1,
                                              backgroundColor: Colors.black45,
                                              textColor: Colors.white,
                                              fontSize: 16.0
                                          );
                                          Future.delayed(Duration(seconds: 2), () {//延时2s跳转登录页面
                                          });
                                        }
                                        var guige = goodsShop['guige'];//商品规格
                                        if(guige.length>2){
                                          params = []; //规格下标
                                          names = []; //选中的规格
                                          panduan = []; //判断规格是否选重复
                                          guigejia = goodsShop['gprice'];//初始化规格价格
                                          guigeList = json.decode(guige);//将规格转为数组
                                          showDialog<Null>(
                                            context: context,
                                            barrierDismissible: true, // 点击窗口外部是否自动关闭
                                            builder: (BuildContext context) {
                                              return StatefulBuilder(builder: (context1, setBottomSheetState){
                                                funCb = setBottomSheetState;
                                                return new AlertDialog(
                                                  title: new Text(goodsShop['gname']),
                                                  content: new SingleChildScrollView(
                                                    child: new ListBody(
                                                      children: <Widget>[
                                                        _showGuigeDetail(guigeList,),
                                                      ],
                                                    ),
                                                  ),
                                                  actions: <Widget>[
                                                    Text("价格:￥"),
                                                    Text("$guigejia",style: TextStyle(fontSize: 20,color: Colors.deepOrange),),
                                                    new FlatButton(
                                                      child: new Container(
                                                        padding: EdgeInsets.symmetric(vertical: 3,horizontal: 6),
                                                        decoration: BoxDecoration(
                                                          borderRadius: BorderRadius.all(Radius.circular(5)) ,
                                                          color: Colors.amberAccent,
                                                        ),
                                                        child: Text('+ 加入购物车',style: TextStyle(color: Colors.black),),
                                                      ),
                                                      onPressed: () async {
                                                        int n = guigeList.length;
                                                        int m = names.length;
                                                        if (m < n) {
                                                          Fluttertoast.showToast(msg: "请选择完整规格");
                                                          return;
                                                        }
                                                        // params = params.sublist(params.length - n);
                                                        // names = names.sublist(names.length - n);
                                                        if (m > 1) {
                                                          //排序
                                                          for (int i = 0;i < n;i++) {
                                                            if (guigeList[i]['name'] != panduan[i]) {
                                                              for (int e = 0; e < panduan.length; e++) {
                                                                if (guigeList[i]['name'] == panduan[e]) {
                                                                  var z = panduan[i];
                                                                  panduan[i] = panduan[e];
                                                                  panduan[e] = z;
                                                                  var y = names[i];
                                                                  names[i] = names[e];
                                                                  names[e] = y;
                                                                  var o = params[i];
                                                                  params[i] = params[e];
                                                                  params[e] = o;
                                                                }
                                                              }
                                                            }
                                                          }
                                                        }
                                                        guiges = json.encode(names);
                                                        guigexiabiao = json.encode(params);
                                                        zongjia = zongjia+guigejia+goodsShop['gdabaofei'];
                                                        zongdabaofei = zongdabaofei+goodsShop['gdabaofei'];
                                                        //加入购物车
                                                        var x = await HttpUtil().get("/waimai/mShopCat/addMGoodscat?mgid=${goodsShop['id']}&userId=${userId}&catnum=1"+"&names="+guiges+"&params="+guigexiabiao+"&money="+goodsShop['gprice'].toString());
                                                        if(x['code']==200){
                                                          int xb=0;
                                                          cartsize++;
                                                          goodsShop['catId']=x['data'];
                                                          goodsShop['catNum']++;
                                                          for(int f=0;f<cartList.length;f++,xb++){
                                                            if(goodsShop['id']==cartList[f]['mgid'] && guiges==cartList[f]['guiges'] && guigexiabiao==cartList[f]['guigeparams']){
                                                              cartList[f]['scatNum']++;
                                                              break;
                                                            }
                                                          }
                                                          if(xb==cartList.length){
                                                            Map map={};
                                                            map['userId']=userId;
                                                            map['mgid']=goodsShop['id'];
                                                            map['scatNum']=1;
                                                            map['money']=goodsShop['gprice'];
                                                            map['id']=x['data'];
                                                            map['guiges']=guiges;
                                                            map['guigeparams']=guigexiabiao;
                                                            Map goodsmap={};
                                                            goodsmap['gimages']=goodsShop['gimages'];
                                                            goodsmap['guige']=goodsShop['guige'];
                                                            goodsmap['gname']=goodsShop['gname'];
                                                            goodsmap['gprice']=goodsShop['gprice'];
                                                            map['mgoods']=goodsmap;
                                                            cartList.add(map);
                                                          }
                                                        }
                                                        setState(() {});
                                                        if (x['code'] == 200) {
                                                          Fluttertoast.showToast(msg: "加入购物车成功");
                                                        } else {
                                                          Fluttertoast.showToast(msg: x['msg']);
                                                        }
                                                        Navigator.pop(context); // 隐藏底部规格选择
                                                        // Navigator.of(context).pop();
                                                      },
                                                    ),
                                                  ],
                                                );
                                              },);
                                            },
                                          ).then((val) {
                                          });
                                        }
                                      },
                                      )
                                    ],
                                  )
                                ],
                              ),
                            ),
                            Container(
                              padding: EdgeInsets.fromLTRB(6, 3, 6, 3),
                              child: Row(children: [Expanded(
                                child: Text("${obj['jianjie']}"),
                              )]),
                              decoration: BoxDecoration(),
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Container(
                                  child: Row(
                                    children: [
                                      Icon(CupertinoIcons.heart),
                                      Text("收藏")
                                    ],
                                  ),
                                ),
                                Container(
                                  child: Row(
                                    children: [
                                      Icon(CupertinoIcons.arrowshape_turn_up_right),
                                      Text("分享")
                                    ],
                                  ),
                                )
                              ],
                            ),
                          ],
                        ),
                      ),
                      Html(
                        data: """${obj['gdetail']}""", // 富文本中的详情
                        style: {
                          // "html": Style(
                          //   backgroundColor: Colors.black12,
                          // ),
                        },
                      )
                    ],
                    )
                )
            ),
            Container(
              margin: EdgeInsets.symmetric(horizontal: 10,vertical: 5),
              padding: EdgeInsets.symmetric(vertical: 5),
              decoration:  new BoxDecoration(
                //背景
                color: Colors.black,
                //设置四周圆角 角度
                borderRadius: BorderRadius.all(Radius.circular(10)),
                //设置四周边框
                border: new Border.all(width: 1, color: Colors.black),
              ),
              child: Center(
                child: Container(
                  width: ScreenUtil().setWidth(450),
                  decoration: BoxDecoration(
                    // borderRadius: BorderRadius.all(Radius.circular(30)) ,
                    // border: Border.all(color: Colors.black , width: 1) ,
                    color: Colors.black,
                  ),
                  margin: EdgeInsets.fromLTRB(0, 0, 0, 5),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      GestureDetector(
                        child:Row(
                          children: [
                            Icon(Icons.shopping_cart,color: Colors.yellow,size: 35,),
                            Container(
                              margin: EdgeInsets.fromLTRB(0, 0, 0, 20),
                              padding: EdgeInsets.all(2),
                              decoration: BoxDecoration(
                                color: Colors.red,
                                borderRadius:BorderRadius.circular(10),
                              ),
                              child: Row(
                                children: [
                                  Text(cartsize.toString(),style: TextStyle(color: Colors.white,fontSize: 13),)
                                ],
                              ),
                            )
                          ],
                        ),onTap: (){
                        cartsize==0 ?
                        Fluttertoast.showToast(
                            msg: "您还未加入商品",
                            toastLength: Toast.LENGTH_SHORT,
                            gravity: ToastGravity.BOTTOM,
                            timeInSecForIosWeb: 1,
                            backgroundColor: Colors.black45,
                            textColor: Colors.white,
                            fontSize: 16.0
                        )
                            :
                        showDialog<Null>(//展示购物车的窗口
                          context: context,
                          barrierDismissible: true, // 点击窗口外部是否自动关闭
                          builder: (BuildContext context) {
                            return StatefulBuilder(
                              builder: (context1,state){
                                funCb = state;
                                return new AlertDialog(
                                  title: new Text("购物车"),
                                  content: new SingleChildScrollView(
                                    child: new ListBody(
                                      children: <Widget>[
                                        showCart(cartList,state,context)
                                      ],
                                    ),
                                  ),
                                );
                              },
                            );
                          },
                        ).then((val) {

                        });
                      },
                      ),
                      Container(
                        // color: Colors.red,
                        margin: EdgeInsets.fromLTRB(0, 0, 100, 0),
                        // padding: EdgeInsets.fromLTRB(0, 0, 150, 0),
                        child: Text("￥${zongjia.toStringAsFixed(2)}",style: TextStyle(color: Colors.white,fontSize: 20),),
                      ),
                      GestureDetector(
                        child: Container(
                          padding: EdgeInsets.symmetric(vertical: 10,horizontal: 20),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(Radius.circular(30)) ,
                            border: Border.all(color: Colors.yellow , width: 1) ,
                            color: Colors.yellow,
                          ),
                          child: Text("去结算",style: TextStyle(color: Colors.black),),
                        ),
                        onTap: () async {
                          // double peisongfei = 10;//配送费
                          // var x = await HttpUtil().get("/waimai/mOder/catSubmitMOrder?userId=$userId&mid=$merchantId&orPeisongtype=2&orRemark=&dabaofei=$zongdabaofei&peisongfei="+peisongfei.toString()+"&orPrice=$zongjiage");
                          if(cartsize>0){
                            //跳订单页面
                            var value = await MyRoute.push(CartOrder(orRemark: "",cartList: cartList,merchantName: merchantName,dabaofei: zongdabaofei,zongjia: (zongjia/100).toString(),cartsize: cartsize,merchantId: merchantId,));
                            if(value==1){
                              for(int x=0;x<cartList.length;x++){
                                cartList.removeAt(x);
                              }
                              goodsShop["catNum"]=0;
                              zongdabaofei=0;
                              zongjia=0;
                              setState(() {

                              });
                            }
                          }else{
                            Fluttertoast.showToast(
                                msg: "请先选择商品",
                                toastLength: Toast.LENGTH_SHORT,
                                gravity: ToastGravity.BOTTOM,
                                timeInSecForIosWeb: 1,
                                backgroundColor: Colors.black45,
                                textColor: Colors.white,
                                fontSize: 16.0
                            );
                          }
                        },
                      )
                    ],),
                ),
              ),
            )
            // Row(
            //   children: [
            //     Container(
            //       child:
            //           Column(children: [Icon(CupertinoIcons.cube), Text("店铺")]),
            //       width: ScreenUtil().setWidth(58),
            //       decoration: BoxDecoration(),
            //     ),
            //     Container(
            //         width: ScreenUtil().setWidth(58),
            //         child: Column(children: [
            //           Icon(CupertinoIcons.headphones),
            //           Text("客服")
            //         ])),
            //     Container(
            //         width: ScreenUtil().setWidth(58),
            //         child: Column(
            //             children: [Icon(CupertinoIcons.star), Text("收藏")]
            //         )
            //     ),
            //     Expanded(child: Text("")),
            //     GestureDetector(
            //         child: Container(
            //           margin: EdgeInsets.only(right: 10),
            //           width: ScreenUtil().setWidth(145),
            //           height: ScreenUtil().setHeight(50),
            //           child: Center(
            //               child: Text("加入购物车",
            //                   style: TextStyle(color: Colors.white))
            //           ),
            //           decoration: BoxDecoration(color: Colors.amberAccent),
            //         ),
            //         onTap: () async {
            //           String names = ""; //规格
            //           String params = ""; //规格下标
            //           money = obj['gprice']; //金额
            //           SharedPreferences prefs = await SharedPreferences.getInstance();
            //           userId = prefs.getString("userId"); //用户ID
            //           if (userId == null || userId == "") {
            //             Fluttertoast.showToast(msg: "请先登录");
            //             //延时2s执行返回
            //             Future.delayed(Duration(seconds: 2), () {
            //               MyRoute.replace(Login());
            //             });
            //           }
            //           //加入购物车
            //           if (guige == null) {
            //             // 如果没有规格
            //             var x = await HttpUtil().get(
            //                 "/app/shopCat/addGoodscat?gid=" +
            //                     "${obj['gid']}" +
            //                     "&userId=" +
            //                     userId +
            //                     "&catnum=1" +
            //                     "&names=" +
            //                     names +
            //                     "&params=" +
            //                     params +
            //                     "&money=" +
            //                     money.toString());
            //             if (x['code'] == 200) {
            //               Fluttertoast.showToast(msg: "加入购物车成功");
            //             } else {
            //               Fluttertoast.showToast(msg: x['msg']);
            //             }
            //           } else {
            //             // 显示规格
            //             showModalBottomSheet(
            //               context: context,
            //               builder: (BuildContext context) {
            //                 return _showGuige(1);
            //               },
            //             ).then((val) {
            //               print(val);
            //             });
            //           }
            //         }),
            //     // GestureDetector(
            //     //   child: Container(
            //     //     width: ScreenUtil().setWidth(145),
            //     //     height: ScreenUtil().setHeight(50),
            //     //     child: Center(
            //     //         child: Text(
            //     //       "立即购买",
            //     //       style: TextStyle(color: Colors.white),
            //     //     )),
            //     //     decoration: BoxDecoration(color: Colors.red),
            //     //   ),
            //     //   onTap: () async {
            //     //     SharedPreferences prefs =
            //     //         await SharedPreferences.getInstance();
            //     //     // String userId = prefs.getString("userId");//用户ID
            //     //     bool isLogin = prefs.getBool("isLogin");
            //     //     if (!isLogin) {
            //     //       Fluttertoast.showToast(msg: "请先登录");
            //     //       Future.delayed(Duration(seconds: 2), () {
            //     //         MyRoute.replace(Login());
            //     //       });
            //     //     } else {
            //     //       //传商品ID，商品名称，商品价格，商品图片，商品单位，运费，规格，规格下标
            //     //       if (guige == null) {
            //     //         String gid = obj['gid'];
            //     //         MyRoute.push(LjgmOrder(
            //     //             gid: gid, names: guiges, params: guigexiabiao));
            //     //       } else {
            //     //         // 显示规格
            //     //         showModalBottomSheet(
            //     //           context: context,
            //     //           builder: (BuildContext context) {
            //     //             return _showGuige(2);
            //     //           },
            //     //         ).then((val) {
            //     //           print(val);
            //     //         });
            //     //       }
            //     //     }
            //     //   },
            //     // )
            //   ],
            // )
          ],
        ));
  }

  //子窗口显示购物车
  Widget showCart(list,state,context){
    List<Widget> col = [];
    for(int i=0;i<list.length;i++){
      col.add(
          Container(
            margin: EdgeInsets.only(left: 0, top: 5),
            //设置 child 居中
            alignment: Alignment(0, 0),
            height: ScreenUtil().setHeight(120),
            width: ScreenUtil().setWidth(300),
            //边框设置
            decoration: BoxDecoration(
              border:Border(bottom:BorderSide(width: 1,color: Colors.grey)),
            ),
            child: Row(
              children: [
                CachedNetworkImage(imageUrl: Config.getInstance().getHost()+list[i]['mgoods']['gimages'],width: 70,height: 70,),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      width: ScreenUtil().setWidth(150),
                      height: ScreenUtil().setHeight(30),
                      child: Row(
                        children: [
                          Expanded(child: Text(list[i]['mgoods']['gname']),),
                        ],
                      ),
                    ),
                    Container(
                      width: ScreenUtil().setWidth(150),
                      height: ScreenUtil().setHeight(50),
                      child: Row(
                        children: [
                          Expanded(
                            child: Text(
                              list[i]['guiges']==null ? "" : getGuigeString(list[i]['mgoods']['guige'],list[i]['guigeparams']),
                              style: TextStyle(fontSize: 10),
                            ),
                          )
                        ],
                      ),
                    ),
                    Row(
                      children: [
                        Container(
                          width: ScreenUtil().setWidth(70),
                          child: Row(
                            children: [
                              Text("￥",style: TextStyle(fontSize: 12,color: Colors.red)),
                              Text(list[i]['money'].toString(),style: TextStyle(fontSize: 15,color: Colors.red))
                            ],
                          ),
                        ),
                        SizedBox(width: ScreenUtil().setWidth(50),),
                        Row(
                          children: [
                            GestureDetector(
                              child: Container(
                                decoration:  new BoxDecoration(
                                  //背景
                                  color: Colors.white,
                                  //设置四周圆角 角度
                                  borderRadius: BorderRadius.all(Radius.circular(4.0)),
                                  //设置四周边框
                                  border: new Border.all(width: 1, color: Colors.orangeAccent),
                                ),
                                width: 15,
                                height: 20,
                                child: Center(
                                  child: Text("-"),
                                ),
                                padding: EdgeInsets.fromLTRB(1, 0, 0, 1),
                              ),
                              onTap: () async {
                                List gList= [];
                                for(int i=0;i<goodsTypeList.length;i++){
                                  var list= goodsTypeList[i]['mgoodsList'];
                                  for(int j=0;j<list.length;j++){
                                    gList.add(list[j]);
                                  }
                                }
                                if(list[i]['scatNum']>0){
                                  for(int j=0;j<gList.length;j++){
                                    if(list[i]['userId']==userId && list[i]['mgid']==gList[j]['id']){
                                      var x = await HttpUtil().get("/waimai/mShopCat/gaiNum?scatId=${list[i]['id']}&type=1");
                                      if(x['code']==200){
                                        zongjia = zongjia-gList[j]['gprice']-gList[j]['gdabaofei'];
                                        zongdabaofei = zongdabaofei-gList[j]['gdabaofei'];
                                        cartsize--;
                                        gList[j]['catNum']--;
                                        list[i]['scatNum']--;
                                        if(list[i]['scatNum']<=0){
                                          cartList.removeAt(i);
                                        }
                                      }
                                      state(() {

                                      });
                                      setState(() {

                                      });
                                      if(cartsize<=0){
                                        Navigator.pop(context);
                                      }
                                      break;
                                    }
                                  }
                                }
                              },
                            ),
                            SizedBox(width: ScreenUtil().setWidth(5),),
                            Container(
                              width: 25,
                              child: Center(
                                child:Text(list[i]['scatNum'].toString()),
                              ),
                            ),
                            SizedBox(width: 6,),
                            GestureDetector(
                              child: Container(
                                decoration:  new BoxDecoration(
                                  //背景
                                  color: Colors.orangeAccent,
                                  //设置四周圆角 角度
                                  borderRadius: BorderRadius.all(Radius.circular(4.0)),
                                  //设置四周边框
                                  border: new Border.all(width: 1, color: Colors.orangeAccent),
                                ),
                                width: 15,
                                height: 20,
                                child: Center(
                                  child: Text("+"),
                                ),
                                padding: EdgeInsets.fromLTRB(1, 0, 0, 1),
                              ),
                              onTap: () async {
                                List gList= [];
                                for(int i=0;i<goodsTypeList.length;i++){
                                  var list= goodsTypeList[i]['mgoodsList'];
                                  for(int j=0;j<list.length;j++){
                                    gList.add(list[j]);
                                  }
                                }
                                if(list[i]['scatNum']>0){
                                  for(int j=0;j<gList.length;j++){
                                    if(list[i]['userId']==userId && list[i]['mgid']==gList[j]['id']){
                                      var x = await HttpUtil().get("/waimai/mShopCat/gaiNum?scatId=${list[i]['id']}&type=2");
                                      if(x['code']==200){
                                        zongjia = zongjia+gList[j]['gprice']+gList[j]['gdabaofei'];
                                        zongdabaofei = zongdabaofei+gList[j]['gdabaofei'];
                                        cartsize++;
                                        gList[j]['catNum']++;
                                        list[i]['scatNum']++;
                                      }
                                      state(() {

                                      });
                                      setState(() {

                                      });
                                      break;
                                    }
                                  }
                                }
                              },
                            ),
                          ],
                        )
                      ],
                    )
                  ],
                )
              ],
            ),
          )
      );
    }
    return Column(
        children: col
    );
  }

  //解析购物车商品的规格
  String getGuigeString(val,params){
    List list=json.decode(val);
    List param=json.decode(params);
    int size=param.length;
    String str='';
    for(int i=0;i<size;i++){
      String value=list[i]['value'];
      var array=value.split('-');
      str+=list[i]['name']+":"+array[param[i]]+" ";
    }
    return str;
  }

  // 循环显示规格界面中的参数
  Widget _showGuigeDetail(guige) {
    List<Widget> col = [];
    for (var i = 0; i < guige.length; i++) {
      List<String> x = [];
      var values = guige[i]['value'].split('-');
      for (var j = 0; j < values.length; j++) {
        x.add(values[j].toString());
      }
      col.add(Align(
        child: Text(guige[i]['name']),
        alignment: Alignment.topLeft,
      )); // 规格名称
      col.add(GroupButton(
          isRadio: true,
          spacing: 10,
          borderRadius: BorderRadius.all(Radius.circular(5)),
          onSelected: (index, isSelected) {
            int n = -1;
            if (panduan.contains(guige[i]['name'])) {
              for (var x = 0; x < names.length; x++) {
                var ttt = names[x][guige[i]['name']];
                if (ttt != null && ttt != "") {
                  n = x;
                  break;
                }
              }
            }
            int xiabiao = int.parse('$index');
            if (n == -1) {
              panduan.add(guige[i]['name']);
              params.add(xiabiao);
              names.add({guige[i]['name']: values[xiabiao]});
            } else {
              params[n] = xiabiao;
              names[n][guige[i]['name']] = values[xiabiao];
            }
            // 此处更新显示的规格价格
            funCb(() {});
          },
          buttons: x));
    }
    return StatefulBuilder(builder: (context1, setBottomSheetState) {
      funCb = setBottomSheetState;
      return Container(
        child: Column(children: col),
      );
    });
  }

  Widget _swiperBuilder(BuildContext context, int index) {
    return (CachedNetworkImage(
      imageUrl: _imageUrls[index],
      fit: BoxFit.fill,
    ));
  }

  // Set selectGuige=new Set(); // 选择的规格
  // var map = new Map();//选择的规格
  //显示规格
  // Widget _showGuige(aaa) {
  //   return StatefulBuilder(builder: (context1, setBottomSheetState) {
  //     funCb = setBottomSheetState;
  //     return Container(
  //       height: 350.0,
  //       child: Column(
  //         children: [
  //           Text("请选择规格"),
  //           Divider(),
  //           Container(
  //             child: Row(
  //               children: [
  //                 CachedNetworkImage(
  //                   imageUrl: Config.getInstance().getHost() + obj['gimages'],
  //                   width: 60,
  //                   height: 60,
  //                 ),
  //                 Column(
  //                   children: [
  //                     // Text("￥${obj['gprice']}"),
  //                     Text("￥${money}"),
  //                   ],
  //                 ),
  //               ],
  //             ),
  //           ),
  //           _showGuigeDetail(),
  //           Expanded(
  //               child: Stack(
  //             children: [
  //               Positioned(
  //                 bottom: 0,
  //                 left: ScreenUtil().setWidth(180),
  //                 child: GestureDetector(
  //                   child: Center(
  //                     child: Container(
  //                       child: Text("确定"),
  //                       padding: EdgeInsets.symmetric(vertical: 10,horizontal: 30),
  //                       decoration: BoxDecoration(color: Colors.orangeAccent),
  //                     ),
  //                   ),
  //                   onTap: () async {
  //                     // setBottomSheetState(() {
  //                     //   // 此句代码可用更新选择的规格价格
  //                     // });
  //                     // print("点击了确定");
  //                     int n = guige['select_guiges'].length;
  //                     int m = names.length;
  //                     if (m < n) {
  //                       Fluttertoast.showToast(msg: "请选择完整规格");
  //                       return;
  //                     }
  //                     params = params.sublist(params.length - n);
  //                     names = names.sublist(names.length - n);
  //                     if (m > 1) {
  //                       //排序
  //                       for (int i = 0;
  //                           i < guige['select_guiges'].length;
  //                           i++) {
  //                         if (guige['select_guiges'][i]['name'] != panduan[i]) {
  //                           for (int e = 0; e < panduan.length; e++) {
  //                             if (guige['select_guiges'][i]['name'] ==
  //                                 panduan[e]) {
  //                               var z = panduan[i];
  //                               panduan[i] = panduan[e];
  //                               panduan[e] = z;
  //                               var y = names[i];
  //                               names[i] = names[e];
  //                               names[e] = y;
  //                               var o = params[i];
  //                               params[i] = params[e];
  //                               params[e] = o;
  //                             }
  //                           }
  //                         }
  //                       }
  //                     }
  //                     if (params.length == 1) {
  //                       money =
  //                           double.parse(guige['values'][params[0]]['jiage']);
  //                     } else if (params.length == 2) {
  //                       money = double.parse(guige['values'][params[0]]
  //                           ['children'][params[1]]['jiage']);
  //                     } else {
  //                       money = double.parse(guige['values'][params[0]]
  //                               ['children'][params[1]]['children'][params[2]]
  //                           ['jiage']);
  //                     }
  //                     // guiges = names.toString();//规格
  //                     // guigexiabiao = params.toString();//规格下标
  //                     // print("规格："+guiges);
  //                     // print("规格下标："+guigexiabiao);
  //                     // guiges = guiges.substring(1,guiges.length-1);
  //                     // guigexiabiao = guigexiabiao.substring(1,guigexiabiao.length-1);
  //                     guiges = json.encode(names);
  //                     guigexiabiao = json.encode(params);
  //                     // print("规格："+guiges);
  //                     // print("规格下标："+guigexiabiao);
  //                     if (aaa == 1) {
  //                       // print("规格价格："+money.toString());
  //                       var x = await HttpUtil().get(
  //                           "/app/shopCat/addGoodscat?gid=" +
  //                               "${obj['gid']}" +
  //                               "&userId=" +
  //                               userId +
  //                               "&catnum=1" +
  //                               "&names=" +
  //                               guiges +
  //                               "&params=" +
  //                               guigexiabiao +
  //                               "&money=" +
  //                               money.toString());
  //                       if (x['code'] == 200) {
  //                         Fluttertoast.showToast(msg: "加入购物车成功");
  //                       } else {
  //                         Fluttertoast.showToast(msg: x['msg']);
  //                       }
  //                       // print(params);
  //                       // print(names);
  //                       // print(panduan);
  //                       // var x = selectGuige.toSet();
  //                       // print(x);
  //                       Navigator.pop(context); // 隐藏底部规格选择
  //                       names = [];
  //                       params = [];
  //                       panduan = [];
  //                     } else {
  //                       String gid = obj['gid'];
  //                       MyRoute.push(LjgmOrder(
  //                           gid: gid,
  //                           names: guiges,
  //                           params: guigexiabiao,
  //                           money: money));
  //                     }
  //                   },
  //                 ),
  //               )
  //             ],
  //           ))
  //         ],
  //       ),
  //     );
  //   });
  // }

  // 循环显示规格界面中的参数
  // Widget _showGuigeDetail() {
  //   // names = [];
  //   // params = [];
  //   // panduan = [];
  //   List<Widget> col = [];
  //   // print(guige);
  //   // print(guige['select_guiges']);
  //   for (var i = 0; i < guige['select_guiges'].length; i++) {
  //     // print(guige['select_guiges'][i]['values']);
  //     List<String> x = [];
  //     for (var j = 0; j < guige['select_guiges'][i]['values'].length; j++) {
  //       x.add(guige['select_guiges'][i]['values'][j]['value'].toString());
  //     }
  //     col.add(Align(
  //       child: Text(guige['select_guiges'][i]['name']),
  //       alignment: Alignment.topLeft,
  //     )); // 规格名称
  //     col.add(GroupButton(
  //         isRadio: true,
  //         spacing: 10,
  //         onSelected: (index, isSelected) {
  //           int n = -1;
  //           if (panduan.contains(guige['select_guiges'][i]['name'])) {
  //             for (var x = 0; x < names.length; x++) {
  //               var ttt = names[x][guige['select_guiges'][i]['name']];
  //               if (ttt != null && ttt != "") {
  //                 n = x;
  //                 break;
  //               }
  //             }
  //           }
  //           int xiabiao = int.parse('$index');
  //           if (n == -1) {
  //             // true
  //             panduan.add(guige['select_guiges'][i]['name']);
  //             params.add(xiabiao);
  //             names.add({
  //               guige['select_guiges'][i]['name']: guige['select_guiges'][i]
  //                   ['values'][xiabiao]['value']
  //             });
  //           } else {
  //             params[n] = xiabiao;
  //             names[n][guige['select_guiges'][i]['name']] =
  //                 guige['select_guiges'][i]['values'][xiabiao]['value'];
  //           }
  //           if (params.length == guige['select_guiges'].length) {
  //             if (params.length == 1) {
  //               money = double.parse(guige['values'][params[0]]['jiage']);
  //             } else if (params.length == 2) {
  //               money = double.parse(
  //                   guige['values'][params[0]]['children'][params[1]]['jiage']);
  //             } else {
  //               money = double.parse(guige['values'][params[0]]['children']
  //                   [params[1]]['children'][params[2]]['jiage']);
  //             }
  //             print("规格金额：" + money.toString());
  //           }
  //           // 此处更新显示的规格价格
  //           funCb(() {});
  //         },
  //         buttons: x));
  //   }
  //   return Container(
  //     child: Column(children: col),
  //   );
  // }
}
